<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\Article;
use Illuminate\Http\Request;

class MyArticleController extends Controller
{
    /**
     * Notes:文章列表展示
     * User: 沐辞
     * Date: 2021/11/18
     * Time: 14:40
     */
    public function articleSel(Request $request)
    {


        $uid =$request->get('uid');

        if (empty($uid)){
            return json_encode(['code'=>999,'msg'=>'请先登录','data'=>'']);
        }
        $articleData = Article::where('uid',$uid)->paginate(5);

        if ($articleData)
        {
            return json_encode(['code'=>200,'msg'=>'查询成功!','data'=>$articleData]);
        }else{
            return json_encode(['code'=>500,'msg'=>'数据为空!','data'=>'']);

        }
    }


    /**
     * Notes:文章列表展示
     * User: 沐辞
     * Date: 2021/11/18
     * Time: 14:40
     */
    public function articleDetails(Request $request)
    {
        //用户ID
        $uid =$request->get('uid');
        //文章ID
        $id  =$request->get('id');
        if (empty($uid)){
            return json_encode(['code'=>999,'msg'=>'请先登录','data'=>'']);
        }
        //查询单条文章数据
        $articleData = Article::find($id);
        if ($articleData)
        {
            //文章浏览量加1
            $articleData = Article::increment('number_views',1,['id'=>$id]);

            return json_encode(['code'=>200,'msg'=>'查询成功!','data'=>$articleData]);
        }else{
            return json_encode(['code'=>500,'msg'=>'数据为空!','data'=>'']);

        }
    }



}
